import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/Login.vue')
  },
  {
    path: '/productDetails',
    name: 'productDetails',
    component: () => import('../views/ProductDetails.vue'),
    meta: {
      isAuth: true
    }
  },
  {
    path: '/selectgoods',
    name: 'selectgoods',
    component: () => import('../views/selectGoods.vue'),
    meta: {
      isAuth: true
    }
  },
  // {
  //   path: '/myinfor',
  //   name: 'myinfor',
  //   component: () => import('../views/my/MyInfor.vue'),
  //   meta: {
  //     isAuth: true
  //   }
  // },
  {
    path: '/shop',
    name: 'shop',
    component: () => import('../views/Shop.vue'),
    redirect: 'shop/goods',
    children: [
      {
        path: 'my',
        name: 'my',
        component: () => import('../views/home/My.vue'),
        meta: {
          isAuth: true
        },
        children: [
        ]
      },
      {
        path: 'order',
        name: 'order',
        component: () => import('../views/home/Order.vue'),
        meta: {
          isAuth: true
        },
        // redirect: '/shop/order/allOrder',
        children: [
          {
            path: 'allOrder',
            name: 'allOrder',
            component: () => import('../components/Oreder/AllOrder.vue'),
            meta: { isAuth: true }
          },
          {
            path: 'deliveryOrder',
            name: 'deliveryOrder',
            component: () => import('../components/Oreder/DeliveryOrder.vue'),
            meta: { isAuth: true }
          },
          {
            path: 'payOrder',
            name: 'payOrder',
            component: () => import('../components/Oreder/PayOrder.vue'),
            meta: { isAuth: true }
          },
          {
            path: 'receiptOrder',
            name: 'receiptOrder',
            component: () => import('../components/Oreder/ReceiptOrder.vue'),
            meta: { isAuth: true }
          }
        ]
      },
      {
        path: 'goods',
        name: 'goods',
        component: () => import('../views/home/Goods.vue'),
        meta: {
          isAuth: true
        }
      },
      {
        path: 'car',
        name: 'car',
        component: () => import('../views/home/Car.vue'),
        meta: {
          isAuth: true
        },
        children: [
        ]
      },
      {
        path: 'Myinfor',
        name: 'Myinfor',
        component: () => import('../views/my/MyInfor.vue'),
        meta: {
          isAuth: true
        }
      }
    ]
  }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  if (to.path === '/shop/goods' || to.path === '/login') {
    console.log('通过路由1')
    next()
  }
  if (to.meta.isAuth && sessionStorage.getItem('token')) {
    // console.log(from)
    next()
  } else {
  }
})

export default router
